package summer.dp;

public class Solution213 {
    public int rob(int[] nums) {
        return Math.max(robAct(nums, 0, nums.length - 2), robAct(nums, 1, nums.length - 1));
    }

    public int robAct(int[] nums, int i, int j) {
        int a = 0;
        int b = 0;
        int cur;
        for (int k = i; k <= j; k++) {
            cur = Math.max(b, a + nums[k]);
            a = b;
            b = cur;
        }
        return b;
    }
}
